//
//  ZQMoneyCell.m
//  jianzhik
//
//  Created by huami on 2018/8/28.
//  Copyright © 2018年 WKWebView. All rights reserved.
//
#import "UIView+zq_extension.h"
#import "ZQMoneyCell.h"
#import "ZQ_GetCurrentViewNavTool.h"
@implementation ZQMoneyCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setModels:(ZQMoneyModels *)models
{
    _models = models;
    self.bTypeLabel.text = models.Symbol;
    NSLog(@"model.fee==%@",@(models.Fee));

    self.kgfLabel.text = [NSString stringWithFormat:@"矿工费：%@",[self stringWithDecimalNumber:models.Fee]];

    self.hyAddressLabel.text = models.Contract.length > 0 ? models.Contract : @"合约地址为空";
}
- (IBAction)deleteMoneyBtnClick:(id)sender {
    UIAlertController * alert = [UIAlertController
                                 alertControllerWithTitle:@"温馨提示"
                                 message:@"是否删除币种"
                                 preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction* yesButton = [UIAlertAction
                                actionWithTitle:@"确认"
                                style:UIAlertActionStyleDestructive
                                handler:^(UIAlertAction * action) {
                                    NSLog(@"提交后%@",alert.textFields.lastObject.text);
                                    [self deleteModel];
//                                    [self changeKGF:alert];
                                    
                                }];
    
    UIAlertAction* noButton = [UIAlertAction
                               actionWithTitle:@"取消"
                               style:UIAlertActionStyleDefault
                               handler:^(UIAlertAction * action) {
                                   //Handle no, thanks button
                               }];
    
//    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//        textField.placeholder = @"请在此输入矿工费数值";
//    }];
    
    [alert addAction:yesButton];
    [alert addAction:noButton];
    [[ZQ_GetCurrentViewNavTool viewControllerSupportView:self] presentViewController:alert animated:YES completion:nil];
}

- (void)deleteModel
{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"Id"] = self.models.Id;
    [ZQAFHelper afnetworkRequestWithPostURL:@"/v1/user/delcoin" parameters:parameters view:[ZQ_GetCurrentViewNavTool viewControllerSupportView:self].view finishedBlcok:^(NSDictionary *dict) {
        SendNotify(@"deleteMoney", nil, @{@"model": self.models});
        [UIHelper showSuccessMessage:@"删除成功" afterHideHud:2 toView:[ZQ_GetCurrentViewNavTool viewControllerSupportView:self].view completion:nil];
    }];
}

- (float)floatWithdecimalNumber:(double)num {
    return [[self decimalNumber:num] floatValue];
}

- (double)doubleWithdecimalNumber:(double)num {
    return [[self decimalNumber:num] doubleValue];
}

- (NSString *)stringWithDecimalNumber:(double)num {
    return [[self decimalNumber:num] stringValue];
}

- (NSDecimalNumber *)decimalNumber:(double)num {
    NSString *numString = [NSString stringWithFormat:@"%lf", num];
    return [NSDecimalNumber decimalNumberWithString:numString];
}


@end
